package tenantchannellogic

import (
	"context"
	tenantChannel "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/tenant/channel"
	schema "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/tenant/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type WavepayCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewWavepayCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WavepayCreateLogic {
	return &WavepayCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// WavepayCreate wavepay
func (l *WavepayCreateLogic) WavepayCreate(in *rpc.WavepayCreateRequest) (*rpc.WavepayCreateResponse, error) {
	var CommonResp rpc.CommonResp
	wavepay := &schema.TenantChannelWavepay{
		Code:         in.Code,
		Phone:        in.Phone,
		CardHolder:   in.CardHolder,
		MinAmount:    in.MinAmount,
		MaxAmount:    in.MaxAmount,
		DailyTimes:   in.DailyTimes,
		DailyAmount:  in.DailyAmount,
		RemainTimes:  in.RemainTimes,
		RemainAmount: in.RemainAmount,
		VisionLevel:  in.VisionLevel,
		IsDisplay:    in.IsDisplay,
	}
	err := tenantChannel.NewTenantChannelWavepayModel(l.ctx, l.svcCtx.Db).CreateWavepay(wavepay)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Database operation error"
		return &rpc.WavepayCreateResponse{
			CommonResp: &CommonResp,
		}, err
	}
	CommonResp.Message = "Success"
	return &rpc.WavepayCreateResponse{
		CommonResp: &CommonResp,
	}, nil
}
